﻿using Factory.WarehouseManagement.WarehouseSettings;
using Factory.WarehouseManagement.WarehouseSettings.DTO;
using Microsoft.AspNetCore.Mvc;


namespace Factory.Web.Controllers.WarehouseManagement
{
    public class ReservoirAreaController : Controller
    {
        private readonly IReservoirAreaAppService _reservoirAreaService;


        public ReservoirAreaController(IReservoirAreaAppService reservoirAreaService)
        {
            _reservoirAreaService = reservoirAreaService;
        }

        public IActionResult ReservoirAreaIndex(string setCode)
        {
            ViewBag.SetCode = setCode;
            return View();
        }

        [HttpGet]
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="areaName"></param>
        /// <returns></returns>
        public JsonResult GetReservoirAreaList(string? areaName, string setCode, int page, int limit)
        {
            var arealist = _reservoirAreaService.GetListAsync(areaName, setCode, page, limit);
            return Json(new { data = arealist.Result, code = 0 });
        }

        public IActionResult ReservoirAreaAddIndex()
        {
            return View();
        }

        [HttpPost]
        public JsonResult AddReservoirArea(ReservoirArea input)
        {
            var arealist = _reservoirAreaService.CreateAsync(input);
            return Json(new { code = arealist, msg = "添加成功" });
        }

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <returns>返回对应数据</returns>
        [HttpPost]
        public JsonResult ReservoirAreaDelete(int id)
        {
            var arealist = _reservoirAreaService.DeleteAsync(id);
            return Json(new { code = arealist, msg = "删除成功" });
        }

        public ActionResult ReservoirAreaUpdateIndex(int id)
        {
            ViewBag.Id = id;
            return View();
        }

        [HttpGet]
        public JsonResult GetReservoirAreaById(int id)
        {
            var arealist = _reservoirAreaService.GetReservoirAreaById(id);
            return Json(new { data = arealist, code = 0 });
        }

        [HttpPost]
        public JsonResult UpdateReservoirAreat(ReservoirAreaDTO input)
        {
            var arealist = _reservoirAreaService.UpdateAsync(input);
            return Json(new { code = true, data = arealist });
        }
    }
}
